//
//  NSString+kz_util.m
//  lg_zhinengbeikao_english
//
//  Created by 朱凯 on 2018/12/12.
//  Copyright © 2018年 zhukai. All rights reserved.
//

#import "NSString+kz_util.h"

@implementation NSString (kz_util)

- (NSAttributedString *)attributeStringWithAttributes:(NSDictionary<NSAttributedStringKey, id> *)attributes scope:(NSString *)scope {
    
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:self];
    [attributeString addAttributes:attributes range:[self rangeOfString:scope]];
    return attributeString.copy;
}


#pragma mark - 获得字符串的size（不能用于高度获得）根据字体大小 和 粗细
- (CGSize)getSizeOfString:(float)font{
    
    UIFont *infofont = FONT(font);
    CGSize size = [self sizeWithAttributes:@{NSFontAttributeName: infofont}];
    return size;
}
- (CGSize)getSizeOfBlodString:(float) font{
    
    UIFont *infofont = B_FONT(font);
    CGSize size = [self sizeWithAttributes:@{NSFontAttributeName: infofont}];
    return size;
}


#pragma mark - 获得字符串的rect 根据字体大小 和 展示视图的宽度
- (CGRect)getRectOfStringWithSize:(CGSize)size font:(float)font{
    
    NSDictionary *tdic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:font],NSFontAttributeName,nil];
    CGRect rect = [self boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:tdic context:nil];
    
    return rect;
}
@end
